package com.internetCafes.spms.web.sys.service.impl;

import com.internetCafes.spms.core.model.pageModel.DataGrid;
import com.internetCafes.spms.web.sys.mapper.EducationArticleInfoMapper;
import com.internetCafes.spms.web.sys.model.EducationArticleInfo;
import com.internetCafes.spms.web.sys.service.EducationArticleInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author LinYe
 * @date 2020/10/29
 */
@Service("EducationArticleInfoService")
public class EducationArticleInfoServiceImpl implements EducationArticleInfoService {

    @Autowired
    EducationArticleInfoMapper educationArticleInfoMapper;

    @Override
    public DataGrid dataGrid(Map<String, Object> params, int pageNo, int pageSize) {
        params.put("page", (pageNo - 1 < 0 ? -1 : pageNo - 1) * pageSize);
        params.put("rows", pageSize);
        List<EducationArticleInfo> educationArticleInfoList = educationArticleInfoMapper.selectByParams(params);
        long count = educationArticleInfoMapper.countByParams(params);
        return new DataGrid(educationArticleInfoList, count, pageSize, pageNo);
    }

    @Override
    public int saveEducationArticle(EducationArticleInfo educationArticleInfo) {
        return educationArticleInfoMapper.insert(educationArticleInfo);
    }

    @Override
    public int deleteEducationArticle(Long id) {
        return educationArticleInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateEducationArticle(EducationArticleInfo educationArticleInfo) {
        return educationArticleInfoMapper.updateByPrimaryKey(educationArticleInfo);
    }

    @Override
    public List<EducationArticleInfo> getEducationArticleDetail(Map<String,Object> params) {
        return educationArticleInfoMapper.selectByParams(params);
    }
}
